package com.example.webdemo.controller;

import com.example.webdemo.bean.City;
import com.example.webdemo.service.CityService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Date 2021/6/24 21:27
 * @Created by wangle
 * @Description
 */
@Slf4j
@Controller
public class sqlcontroller {

    JdbcTemplate jdbcTemplate;
    @Autowired
    CityService cityService;

    @ResponseBody
    @GetMapping("/city")
    public City GetCityById(@RequestParam("id") int id){
            return  cityService.GetcityById(id);

    }

    @ResponseBody
    @PostMapping("/savecity")
    public  int saveCity( City city){

            return  cityService.saveCity(city);
    }


    @GetMapping("/sql")
    void contextLoads() {

        Long a= jdbcTemplate.queryForObject("select count(*)  from user",Long.class);
        log.info("记录总数{}",a);
    }
}
